<?php

/*

  Action	$4

  Do this twice: Trash a card from your hand; gain a card costing exactly $1 more than the trashed card.

 */

class Remake extends Card implements iAction, iKingdom, iCornucopia {

    public function __construct() {
        parent::__construct("Remake", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "Do this twice: Trash a card from your hand; gain a card costing exactly $1 more than the trashed card.");
    }

    public function play(Game $game, $isRealCard) {

        for ($i = 0; $i < 2; $i++) {
            $cards = $game->getPlayHand();

            if (sizeof($cards) > 0) {
                $cards = getUniqueCards($cards);
                if (sizeof($cards) > 1) {
                    $output = MySocket::GetUserReply($game, Input_ChooseOne, $cards, 1, 1, null, "Choose card for remake");
                    $card_name = $output[0];
                } else {
                    $card_name = $cards[0];
                }
                $card = $game->moveCardFromPileToPile($card_name, PlayHand, Trash);
                ScreenDisplay::addScreenMessage($game, true, "trash " . nicePrint($card), "trashes " . ScreenDisplay::$LMSG);

                $price = $card->getPrice($game);
                $new_price = $price->add(1);
                $optional_cards = $game->getBoardCardsByPrice($new_price, $new_price);
                if (sizeof($optional_cards) > 0) {

                    if (sizeof($optional_cards) > 1) {
                        $output = MySocket::GetUserReply($game, Input_ChooseOne, $optional_cards, 1, 1, null, "Choose remaked card");
                        $card_name = $output[0];
                    }
                    else {
                        $card_name = $optional_cards[0];
                    }
                    
                    $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile);
                    ScreenDisplay::addScreenMessage($game, false, " and gain " . nicePrint($card), " and gains " . ScreenDisplay::$LMSG);
                }
                else {
                    ScreenDisplay::addScreenMessage($game, false, " and gain nothing" , " and gains nothing");
                }
            }
        }

        $game->cardActionFinished();
        return true;
    }

}

?>